home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: lewkbj@ix.netcom.com (leonel wizel )
- Newsgroups: comp.lang.c++
- Subject: I need some help with a homework
- Date: 19 Feb 1996 02:43:27 GMT
- Organization: Netcom
- Message-ID: <4g8o4f$m93@ixnews7.ix.netcom.com>
- NNTP-Posting-Host: ix-nyc20-01.ix.netcom.com
- X-NETCOM-Date: Sun Feb 18 6:43:27 PM PST 1996
-
-
- I need some help with a homework, that is very difficult for me to
- figure it out. I understand the concept of the language but I am
- having trouble to find wharever I am doing wrong.
-
- The program suppose to
-
- Enter hours worked (-1 to end): 39
- enter hourly rate of the worker ($00:00): 10.00
- salary is $390.00
-
- Enter hours worked (-1 to end): 40
- enter hourly rate of the worker ($00:00): 10.00
- salary is $400.00
-
- Enter hours worked (-1 to end): 41
- Enter hourly rate of the worker ($00:00): 10.00
- salary is $415.00
-
- Enter hours worked (-1 to end): -1
-
- no more hours to enter.
-
- the following program I wrote but, only gives me one amout which is
- $390.00, it supposse to give me the second amount which is 400.00
- but, it keeps repeating the same figure which is 390.00
-
- I need some help please;
-
- The program is as follows:
-
- #include <iostream.h>
- #include <iomanip.h>
-
- main()
- {
- //initialization phase
-
- float hour_rate, salary, hours_worked;
-
-
- cout << "Enter hours worked (-1 to end): ";
- cin >> hours_worked;
-
- if (hours_worked != 1)
- {
- cout << "Enter hourly rate of the worker ($00.00): ";
- cin >> hour_rate;
- }
-
- //processing phase
-
- while (hours_worked != -1)
- {
- if (hours_worked > 40)
- {
- salary = hours_worked * hour_rate + (hour_worked * 1.5 * hour_rate);
- }
- else
- salary = hours_worked * hour_rate;
-
- cout << "The salary for the employee is: \n"
- << setiosflags(ios::fixed | ios::showpoint)
- << setprecision(2) << salary << endl;
-
- cout << endl;
-
- cout <<"Enter hours worked (-1 to end): ";
- cin >> hour_rate;
-
- if (hours_worked != -1)
- {
- cout << "Enter hourly rate of the worker ($00.00): ";
- cin >> hour_rate;
- }
- }
-
- //termination phase
-
- if (hours_worked == -1)
- {
- cout << endl;
- cout << "no hours were entered";
- }
-
- return 0;
- }
-
- the problem is that is giving only one figure which is $390.00, and
- then is
- not clearing the buffer and when I enter another number is keeps the
- same amount in memory which is 390.00. If I tried to end it, it won't
- end it will give me the second line which is "Enter hourly rate of the
- worker ($00.00): ";
-
- I need some help with this simple program for some but, very difficult
- for me.
-
- Thank you.
-
-
-
-
-
-
-